<?php

	/**
	* Gestion des Unit�s d'Enseignement (UE)
	*
	*/
	class Unite {
	
		var $CODE_UNITE;
		var $NOM_UNITE;
		var $CODE_ETABLISSEMENT;
		var $CODE_UNIVERSITE;
		var $CODE_DIPLOME;
		var $CODE_NIVEAU;
		var $SEMESTRE;
		var $CODE_DOMAINE;
		var $CODE_MENTION;
		
		var $code;
		
		var $universite;
		var $etablissement;
		var $etablissement_rattach;
		
		
		function getUnitDecision($cin, $decision){
			$db = new Db();
			$db->connect();
			$sql="
				SELECT 
					*
				FROM
					unite
				WHERE
					CIN='$cin'
					";
			if($decision=='NULL') $sql .="AND  decision is NULL ";
			else
			$sql .="AND  decision = '".$decision."'";
			 		
			/*if($decision == 'inc') $sql .="AND  decision = 'inc'";
			else                   $sql .="AND  decision != 'inc'";
			*/
			//echo $sql;
		
			$req_resp = $db->query($sql);
			$res_resp = $db->fetchArray();
				
			$db->disconnect();
			return($res_resp);
		}
		/**
		* Retourne la liste des unit�s d'enseigenement.	
		*
		*
		*/
		function getUnite($resp, $diplome, $niveau, $semestre, $domaine, $mention){
			$db = new Db();
			$db->connect();
			
			
				// Liste des �tablissements d'une Universit�
				$req_resp = $db->query("SELECT * FROM enseignant, ens_ue WHERE enseignant.code = ens_ue.code_ens and enseignant.code = $resp");
				$res_resp = $db->fetchArray();
				
				list($clef,$result)=each($res_resp);
				
				$universite            =  $result[11];
				$etablissement         =  $result[12];
				$etablissement_rattach =  $result[16];
				
				$requete = "SELECT * FROM unite WHERE CODE_UNIVERSITE = $universite ";
				
				if(isset($etablissement_rattach) && $etablissement_rattach!=0)
				$requete .= " and CODE_ETABLISSEMENT = $etablissement_rattach";
				
				else
				$requete .= " and CODE_ETABLISSEMENT = $etablissement";
				
				if($diplome!="")
				$requete .= " and CODE_DIPLOME = $diplome";
				
				if($niveau!="")
				$requete .= " and CODE_NIVEAU = $niveau";				
				
				if($semestre!="")
				$requete .= " and SEMESTRE = '$semestre'";				

				if($domaine!="")
				$requete .= " and CODE_DOMAINE = $domaine";

				if($mention!="")
				$requete .= " and CODE_DOMAINE = $mention";
				
								
				// Liste de unit�s
				$req = $db->query($requete);
				
				//$nbr = $db->numRows();
				
                $res = $db->fetchArray();
			
			return($res);	
			$db->disconnect();
		}
		
		
		// Code de l'unit�
			function getUniteCode($unite){
			    $db = new Db();
			    $db->connect();
				  
				  $requete="SELECT * FROM unite WHERE code_ue = $unite";
				//echo $requete;
				  $req = $db->query($requete);
									
                  $res = $db->fetchArray();
			
				
			$db->disconnect();
			
			return($res);
	   }


		// Code de l'unit�
			function getUniteIndexation($unite){
			    $db = new Db();
			    $db->connect();
				  
				  $requete="SELECT * FROM indexation WHERE code_ue = $unite";
					
				 //echo  $requete;
				  $req = $db->query($requete);
									
                  $res = $db->fetchArray();
			
				
			$db->disconnect();
			
			return($res);
	   }	   
	   
	
	
	function updateUniteIndexation($tab){
			$db = new Db();
			$db->connect();
			
			$sql="UPDATE
					indexation
					
				  SET
				    description         = '".$tab["plan"]."' ,
					mots_cles           = '".$tab["mot_cles"]."' ,
					public_cible        = '".$tab["public_cible"]."' ,
					nature              = '".$tab["prerequis"]."' ,
					objectif            = '".$tab["objectif"]."' 
					
				  WHERE
					code_ue             = '".$tab["code_ue"]."'
					";
					
			echo $sql;
			$req_resp = $db->query($sql);
				
			$db->disconnect();
		
	}
	   
	   
	   // Mise a jour des unités d'enseignement
	   
	   function updateDipInfos($tab){
			$db = new Db();
			$db->connect();
			
			$sql="UPDATE
					unite
					
				  SET
				    code_diplome           = '".$tab["diplome"]."' ,
					code_domaine           = '".$tab["domaine"]."' ,
					code_mention           = '".$tab["mention"]."' ,
					specialite             = '".$tab["specialite"]."' 
					
				  WHERE
					code_ue                = '".$tab["code_ue"]."'
					";
					
			
			$req_resp = $db->query($sql);
				
			$db->disconnect();
			
		}
	   
	   
	   ///-------------------
	   
	   function updateDipInfos2($tab){
			$db = new Db();
			$db->connect();
			
			$sql="UPDATE
					unite
					
				  SET
				    lib_unite        = '".$tab["libelle"]."' ,
					nature_unite     = '".$tab["nature"]."' ,
					code_niveau      = '".$tab["semestre"]."' ,
					volume_cours     = '".$tab["volum_cours"]."',
					volume_TP        = '".$tab["volum_tp"]."',
					volume_TD        = '".$tab["volum_td"]."',
					coeifficient     =  '".$tab["coeifficient"]."',
					credit           = '".$tab["credit"]."'
					
				  WHERE
					code_ue                = '".$tab["code_ue"]."'
					";
					
			echo $sql;
			$req_resp = $db->query($sql);
				
			$db->disconnect();
			
		}
		
		//
		  function updateDescision($decision,$code_ue)
		  {
		  	
				$db = new Db();
			$db->connect();
			
			$sql="UPDATE
					unite
					
				  SET
				    decision        = '".$decision."'
					
				  WHERE
					code_ue                = ".$code_ue." ";
					
			echo $sql;
			$req_resp = $db->query($sql);
				
			$db->disconnect();
			
		  }
		  
		   function getDescisionDesc($decision)
		  {
			return ($decision=='rj'? 'rejet&eacute' : 
					($decision=='inc'? 'incomplet' : 
						($decision=='comp'? 'complet' : 
							($decision=='pp'? 'PP' : 
								($decision=='in'? 'IN' :
									($decision=='ve'? 'VE' :  
										($decision=='mi'? 'MI' : 'En cours'  )
									
									)
								 )
							
							 )
						
						)
					
					)
			
				);
		  }
		  
		  
	   	
    }

?>
